package com.wswy.wzcx.widget.home;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import com.blankj.utilcode.util.SizeUtils;

public class NewsLoadingView extends View {

  public NewsLoadingView(Context context) {
    this(context,null);
  }

  public NewsLoadingView(Context context,
      @Nullable AttributeSet attrs) {
    this(context, attrs,0);
  }

  public NewsLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    paint.setStyle(Style.FILL);
    paint.setColor(Color.parseColor("#2039424D"));


  }

  private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  private Path path = new Path();
  private RectF rect = new RectF();


  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);


    int h = SizeUtils.dp2px(105);

    for (int i = 0; i < 4; i++) {
      canvas.save();
      canvas.translate(0,i*h);
      canvas.drawPath(path,paint);
      canvas.restore();
    }

  }


  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    path.reset();

    //左边图片
    rect.left = SizeUtils.dp2px(20);
    rect.top = 0;
    rect.right = rect.left + SizeUtils.dp2px(100);
    rect.bottom = SizeUtils.dp2px(75);

    path.addRect(rect,Direction.CW);

    //右边第一行
    rect.left = rect.right + SizeUtils.dp2px(15);
    rect.top = 0;
    rect.right = getMeasuredWidth() - SizeUtils.dp2px(32);
    rect.bottom = SizeUtils.dp2px(16);


    path.addRect(rect,Direction.CW);

    //右边第二行
    rect.top = rect.bottom + SizeUtils.dp2px(10);
    rect.right = rect.right - SizeUtils.dp2px(90);
    rect.bottom = rect.top + SizeUtils.dp2px(16);

    path.addRect(rect,Direction.CW);


    //右边第三行
    rect.top = rect.bottom + SizeUtils.dp2px(20);
    rect.right = rect.left + SizeUtils.dp2px(150);
    rect.bottom = rect.top + SizeUtils.dp2px(13);

    path.addRect(rect,Direction.CW);

  }
}
